import { isUrl } from '../utils/utils';

const menuData = [
  {
    name: '充值管理',
    icon: 'pay-circle-o',
    path: 'charge',
    children: [{
      name: '充值码',
      path: 'code',
    }, {
      name: '充值列表',
      path: 'list',
    }, {
      name: '消费金',
      path: 'money'
    }],
  }, {
    name: '活动管理',
    icon: 'inbox',
    path: 'activity',
    children: [{
      name: '活动项目',
      path: 'list',
    }],
  }, {
    name: '商家管理',
    icon: 'shop',
    path: 'buyer',
    children: [{
      name: '商家列表',
      path: 'list',
    }],
  }, {
    name: '会员管理',
    icon: 'team',
    path: 'vip',
    children: [{
      name: '会员列表',
      path: 'list',
    }],
  },
  {
    name: '首页图片设置',
    icon: 'form',
    path: 'banner',
  }, {
    name: '账户',
    icon: 'user',
    path: 'user',
    authority: 'guest',
    children: [{
      name: '登录',
      path: 'login',
    }, {
      name: '注册',
      path: 'register',
    }, {
      name: '注册结果',
      path: 'register-result',
    }],
  },];

function formatter(data, parentPath = '', parentAuthority) {
  return data.map((item) => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
